$(document).ready(function() {
    activityManage.init();

});
var _mmg = null;
var editIndex = undefined;
var activityManage = function(){
    return{
        init: function () {
            _mmg = $('#dg').datagrid({
                url: '/marketing/activityManagePage',
                method: 'post',
                rownumbers: true,
                striped: true,
                nowrap: true,
                pageList: [25, 30, 35],
                idField: 'id', //主键
                onClickRow: 'onClickRow',
                columns: [
                    [
                        {field: 'ck', checkbox: true},
                        {field: 'id', title: 'id', hidden: true},
                        {field: 'AcTitle', title: '标题', width: 300},
                        {field: 'CreateTime', title: '发布时间', width: 150},
                        {field: 'AcTime', title: '活动时间', width: 160},
                        {field: 'AcPlace', title: '活动地点', width: 130},
                        {field: 'AcNumber', title: '活动名额/人', width: 100},
                        {field: 'AcObject', title: '活动对象', width: 150},
                        {
                             field: 'operation',
                             title: '操作',
                             width: 100,
                             type: 'String',
                             formatter: function (val, item, rowIndex) {
                                      return '<span><a href="#" onclick="activityManage.reduction(\''+ item.Id +'\')"><span style="color:blue;">复制链接</span></a></span> &nbsp;   <span><a href="#" onclick="activityManage.recycle(\''+ item.Id +'\')"><span style="color:red;">删除</span></a></span>';
                             }
                             },
                    ]
                ],


            }).datagrid("clientPaging");
        },


        //新增_弹出框
        addPopu: function () {
            $('#w').window('open');
        },
        //关闭弹出框
        closePopu: function () {
            $('#w').window('close');
        },

        //跳转到  回收站列表
        Recycle: function () {
            window.location.href = '/marketing/activityManageRecycle';
        },
        //保存操作
        save: function () {
            var AcTitle= $("#AcTitle").val();
            var AcPlace= $("#AcPlace").val();
            var AcObject= $("#AcObject").val();
            var AcNumber= $("#AcNumber").val();
            var firstAcTime = $("#firstAcTime").datetimebox('getValue');
            var lastAcTime = $("#lastAcTime").datetimebox('getValue');
            var str=' 至 '
            var AcTime=firstAcTime+str+lastAcTime
            var activityContent= $(document.getElementsByTagName('iframe')[0].contentWindow.document.body).html();
            var parmas={AcTitle:AcTitle,AcPlace:AcPlace,AcObject:AcObject,AcNumber:AcNumber,AcTime:AcTime,AcContent:activityContent}
            $.ajax({
                type: 'POST',
                url: '/marketing/addactivity',
                dataType: 'json',
                data: parmas,
                success: function (result) {
                    if (result['info'] == 'Success') {
                        alert("添加活动成功！")
                        activityManage.closePopu();
                        window.location.reload();
                    } else {
                        alert("添加活动失败！")
                    }
                }
            })

        },

        //活动加入回收站
        recycle: function (Id) {
            $.messager.confirm('确认', '确定要加入回收站？', function (r) {
                if (r) {
                    $.ajax({
                        type: 'POST',
                        url: '/marketing/recycleactivitybyid',
                        data: 'Id=' + Id,
                        success: function (result) {
                            if (result['info'] == '1') {
                                alert("加入回收站成功！")
                                window.location.reload();
                                return;
                            } else {
                                alert('加入回收站失败！');
                                return;
                            }
                        }
                    })
                }
            });



        },

    }

}
();

